package com.myecl.poker.view;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

import com.myecl.poker.rules.Card;



public class CardLabel extends JLabel {

	
	private static final long serialVersionUID = 1L;
	
	public CardLabel(Card card) {
		if (card != null) {
			getImage(card.toFilename());
		} else {
			getImage("b1fv");
		}
		this.setSize(71, 96);
	}
	
	public CardLabel(String filename) {
		getImage(filename);
	}
		
	private void getImage(String filename) {
		BufferedImage image = null;
    	try {  
    		InputStream input = CardLabel.class.getResourceAsStream("/main/ressources/cards/" + filename + ".gif");
    		image =  ImageIO.read(input);
         } catch (IOException ex) {
              ex.printStackTrace();
         }
    	this.setIcon(new ImageIcon(image));
	}
}
